import { getNestApiData, getOnelineApiData } from "../../../tools/HttpClient";
// 云模板
export async function templateList(params) {
    try {
        const res = await getOnelineApiData("cpas6.templet.listCPAS", params);
        if (res.ok) {
            return Promise.resolve({
                data: res.data,
                success: true,
            });
        }
        return Promise.resolve({
            data: res.data,
            success: false,
        });
    }
    catch (error) {
        return Promise.resolve({
            data: "接口/template/save,请求失败！",
            success: false,
        });
    }
}
// // 保存模板
// export async function templateSaveApi(params: {
//   dbname: string;
//   templateName: string;
//   tableNames: string[];
//   type: string;
//   dateId?: string;
//   // action: string;
//   // files?: string;
//   // isInsertDB: boolean;
// }) {
//   try {
//     const res = await getNestApiData("/template/exportDataToSqlite", "post", params);
//     if (res.ok) {
//       return Promise.resolve({
//         data: res.data,
//         msg: res.msg,
//         success: true,
//       });
//     }
//     return Promise.resolve({
//       data: res.data,
//       msg: res.msg,
//       success: false,
//     });
//   } catch (error) {
//     return Promise.resolve({
//       data: "接口/template/exportDataToSqlite,请求失败！",
//       success: false,
//     });
//   }
// }
// 查询所有模板信息
export async function templateListApi() {
    try {
        const res = await getNestApiData("/template/list", "get");
        if (res.ok) {
            return Promise.resolve({
                data: res.data,
                msg: res.msg,
                success: true,
            });
        }
        return Promise.resolve({
            data: res.data,
            msg: res.msg,
            success: false,
        });
    }
    catch (error) {
        return Promise.resolve({
            data: "接口/template/list,请求失败！",
            success: false,
        });
    }
}
// 根据模板名查询模板是否存在
export async function templateNameIfExistApi(params) {
    try {
        const res = await getNestApiData("/template/newTemplate", "post", params);
        if (res.ok) {
            return Promise.resolve({
                data: res.data,
                msg: res.msg,
                success: true,
            });
        }
        return Promise.resolve({
            data: res.data,
            msg: res.msg,
            success: false,
        });
    }
    catch (error) {
        return Promise.resolve({
            data: "接口/template/newTemplate,请求失败！",
            success: false,
        });
    }
}
// 初始化模板
export async function templateInitApi(params) {
    try {
        const res = await getNestApiData("/template/init", "post", params);
        if (res.ok) {
            return Promise.resolve({
                data: res.data,
                msg: res.msg,
                success: true,
            });
        }
        return Promise.resolve({
            data: res.data,
            msg: res.msg,
            success: false,
        });
    }
    catch (error) {
        return Promise.resolve({
            data: "接口/template/init,请求失败！",
            success: false,
        });
    }
}
// 下载云端文件
export async function templateCloudDownload(params) {
    try {
        const res = await getNestApiData("/template/cloudDownload", "post", params);
        if (res.ok) {
            return Promise.resolve({
                data: res.data,
                msg: res.msg,
                success: true,
            });
        }
        return Promise.resolve({
            data: res.data,
            msg: res.msg,
            success: false,
        });
    }
    catch (error) {
        return Promise.resolve({
            data: "接口/template/cloudDownload,请求失败！",
            success: false,
        });
    }
}
// 模板的导入
export async function templateImport(params) {
    try {
        const res = await getNestApiData("/template/import", "post", params);
        if (res.ok) {
            return Promise.resolve({
                data: res.data,
                msg: res.msg,
                success: true,
            });
        }
        return Promise.resolve({
            data: res.data,
            msg: res.msg,
            success: false,
        });
    }
    catch (error) {
        return Promise.resolve({
            data: "接口/template/import,请求失败！",
            success: false,
            msg: "网络请求失败",
        });
    }
}
